package com.kaiwukj.android.ufamily.mvp.ui.page.keeper;

import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.kaiwukj.android.ufamily.R;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.KeeperResult;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

public class KeeperServiceAdapter extends BaseQuickAdapter<KeeperResult.KeeperService, BaseViewHolder> {
    public KeeperServiceAdapter() {
        super(R.layout.item_keeper_service, new ArrayList<>());
    }

    @Override
    public long getItemId(int position) {
        return getItem(position) == null ? -1 : getItem(position).getId();
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, KeeperResult.KeeperService keeperService) {
        ImageView ivIcon = holder.getView(R.id.iv_icon);
        holder.setText(R.id.tv_text, keeperService.getServiceName());

        if (keeperService.getId() == -1) {
            ivIcon.setImageResource(Integer.parseInt(keeperService.getServiceIcon()));
        } else {
            Glide.with(getContext())
                    .load(keeperService.getServiceIcon())
                    .into(ivIcon);
        }
    }
}
